import {createRouter, createWebHistory} from 'vue-router'
import HomeView from "@/views/HomeView.vue";
import {ElMessage} from "element-plus";
const routes = [
    {
        path: '/',
        name: 'home',
        component: HomeView,
        redirect: '/jobList',
        meta: { requiresAuth: true }, // 需要登录才能访问
        children: [

            {path: '/cityList', component: ()=> import('../views/citylist/CityListView.vue')},
            {path: '/jobFairs', component: ()=> import('../views/jobmeeting/JobFairsView.vue')},
            {path: '/contactus', component: ()=> import('../views/contactus/ContactUsView.vue')},
            {path: '/companyList', component: ()=> import('../views/companylist/CompanyList.vue')},
            {path: '/companyInfo', component: ()=> import('../views/companylist/CompanyInfoView.vue')},
            {path: '/jobList', component: ()=> import('../views/joblist/JobListView.vue')},
            {path: '/jobInfo', component: ()=> import('../views/joblist/JobInfoView.vue')},

        ]
    },
    {
        path: '/login',
        name: 'login',
        meta: { requiresAuth: false },
        component: () => import('../views/LoginView.vue')
    },
    {
        path: '/user',
        name: 'user',
        component: () => import('../views/user/UserView.vue')
    },
    {
        path: '/applicationRecords',
        name: 'applicationRecords',
        component: () => import('../views/applicationRecords/ApplicationRecordsView.vue')
    },
    {
        path: '/register',
        name: 'register',
        component: () => import('../views/RegisterView.vue')
    },
    {
        path: '/terms-of-service',
        name: 'TermsOfService',
        component: () => import('../views/terms/TermsOfService.vue')
    },
    {
        path: '/privacy-policy',
        name: 'PrivacyPolicy',
        component: () => import('../views/terms/PrivacyPolicy.vue')
    },
    {
        path: '/resume',
        name: 'resume',
        component: () => import('../views/resume/ResuMeView.vue')
    },
    {
        path: '/interestJob',
        name: 'interestJob',
        component: () => import('../views/interestjob/InterestView.vue')
    },
    {
        path: '/candidateRecords',
        name: 'candidateRecords',
        component: () => import('../views/candidateRecords/CandidateRecordsView.vue')
    },
    {
        path: '/interestedJobs',
        name: 'interestedJobs',
        component: () => import('../views/interestedJobs/InterestedJobsView.vue')
    },
    {
        path: '/resumeList',
        name: 'resumeList',
        component: () => import('../views/resume/ResumeListView.vue')
    },
    {
        path: '/editResume',
        name: 'editResume',
        component: () => import('../views/resume/EditBlueResume.vue')
    },
    {
        path: '/resume',
        name: 'resume',
        component: () => import('../views/resume/ResuMeView.vue')
    },
    // {
    //     path: '/verification',
    //     name: 'verification',
    //     component: () => import('../views/notregistered/VerificationView.vue')
    // },
    {
        path: '/verification',
        name: 'verification',
        component: () => import('../views/notregistered/VerificationView.vue')
    },
    {
        path: '/audit',
        name: 'audit',
        component: () => import('../views/notregistered/AuditView(1).vue')
    },
]
const router = createRouter({
    history: createWebHistory(),
    routes
})
    // 路由守卫逻辑
router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token');
    if (to.meta.requiresAuth && !token) {
        next('/login'); // 跳转到登录页
        ElMessage.error('请先登录！'); // 使用Element Plus提示
    } else {
        next(); // 放行
    }
});


export default router
